# #基础
# s = "Hello,Python world!"
#
# #1.字符串长度计算
# print(len(s))
#
# #2.计算字符串中"o"字符的个数
# print(s.count('o'))
#
# #3.将字符串转换为大写
# s = s.upper()
# print(s)
#
# #4.将字符串转换为小写
# s = s.lower()
# print(s)
#
# s = "Hello,Python world!"
#
# #5.查找'Python'在字符串中的位置
# print(s.find('Python'))
#
# #6.替换字符串中的"world"为"universe"
# s = s.replace("world","universe")
# print(s)
#
# #7.检查字符串是否以"Hello"开始
# print(s.startswith('Hello'))
#
# #8.检查字符串是否以"!"结尾
# print(s.endswith('!'))
#
# #9.以","为分隔符，拆分字符串
# s = s.split(",")
# print(s)
#
# s = "Hello,Python world!"
#
# #10.去除字符串首尾的"!"
# s = s.strip("!")
# print(s)
#
# #11.字符串反转
# s = s[::-1]
# print(s)
#
# s = "Hello,Python world!"
#
# #12.字符串切片，获取"Python"
# print(s[6:12])
#
# #13.将字符串s中的'hello,'删除
# s = s.replace("Hello,","")
# print(s)
#
# #14.拼接两个字符串'Hello,'和'World!'
# print("Hello," + "World!")
#
# s = "Hello,Python world!"
#
# #15.使用f-string合并字符串和数字2021
# print(f"{s}2021")
#
# #16.找出'a'第一次出现的位置
# print(s.find("a"))
#
# #17.找出'e'最后一次出现的位置
# print(s.rfind("e"))
#
# #18.计算字符串中空格的数量
# print(s.count(" "))
#
# #19.使用循环遍历字符串中的每个字符
# for i in s:
#     print(i,end = "\t")
# print()
#
# #20.将字符串转为"列表"形式，每个字符为一个列表元素
# list_s = [x for x in s]
# print(list_s)
#
# #21.字符串排序（先转换为列表）
# list_s.sort()
# print(list_s)
#
# #22.判断字符串是否为数字
# print(s.isdigit())
#
# #23.将列表'['Hello,','Python','World!']'使用空格连接成一个字符串
# s = ""
# list_1 = ['Hello,','Python','World!']
# for x in list_1:
#     if s == "":
#         pass
#     else:
#         s += " "
#     s += x
# print(s)
#
# #24.使用%操作符格式化字符串，将数字插入到"Number:"后面
# print("Number:%s" % 100)
#
# #25.检查字符串是否全部为小写字母
# i = 0
# for x in s:
#     if 'a' <= x <= 'z':
#         pass
#     else:
#         i += 1
# if i == 0:
#     print("都是小写字母")
# else:
#     print("并不都是小写字母")
#
# #26.检查字符串是否全部为大写字母
# i = 0
# for x in s:
#     if 'A' <= x <= 'Z':
#         pass
#     else:
#         i += 1
# if i == 0:
#     print("都是大写字母")
# else:
#     print("并不都是大写字母")
#
# #27.将数字列表'[1,2,3]'转换成字符串，元素之间用'-'连接
# s = ""
# list_3 = [1, 2, 3]
# for x in list_3:
#     if s == "":
#         pass
#     else:
#         s += "-"
#     s += str(x)
# print(s)
#
# #28.找出字符串中所有的"o"的位置
# i = 0
# s = "Hello,Python world!"
# for x in s:
#     if x == "o":
#         print(i)
#     i += 1
#
# #29.替换字符串中的第一个"o"为"O"
# s = s.replace("o","O",1)
# print(s)
#
# #30.字符串插入操作，向字符串指定位置插入子字符串"amazing"
# i = 5  #位置
# s_1 = s[:5] + "amazing" + s[5:]
# print(s_1)

#进阶
s = "Python is great!"
print(s)

# #1.编写代码反转字符串
# list_1 = [x for x in s]
# s = ""
# for x in list_1[::-1]:
#     s += x
# print(s)
#
# #2.计算字符't'出现的次数
# print(s.count("t"))

# #3.将空格替换为下划线
# s = s.replace(" ","_")
# print(s)

# #4.检查回文，忽略大小写、标点、空格
# """
# 清洗数据
# 判断回文
# """
# s2 = "A man, a plan, a canal, Panama!"
# s3 = ""
# s4 = ""
# for x in s2:
#     if 'a' <= x <= 'z' or 'A' <= x <= 'Z':
#         s3 += x.lower()
# lis_1 = list(s3)
# list_1 = list_1[::-1]
# for x in lis_1:
#     s4 += x
# print(s4)
# if s3 == s4:
#     print("s2为回文")
# else:
#     print("s2不是回文")

# #5.子字符串查找
# print(s.find("is"))
#
# #6.字符串插入
# i = s.find("t")
# s = s[:i+1] + "_inserted" + s[i+1:]
# print(s)

# #7.部分替换
# s = s.replace("great", "awesome", 1)
# print(s)
#
# #8.切片与拼接
# s = s[5:] + s[:5]
# print(s)

# #9.创建字符串列表，元素为大写形式
# list_2 = [x.upper() for x in s]
# print(list_2)

#10.编写加密函数

# def encrypt(list_1):
#     dictionary_1 = {
#         "a":"b", "b":"c", "c":"d", "d":"e", "e":"f",
#         "f":"g", "g":"h", "h":"i", "i":"j",
#         "j":"k", "k":"l", "l":"m", "m":"n",
#         "n":"o", "o":"p", "p":"q", "q":"r",
#         "r":"s", "s":"t", "t":"u", "u":"v",
#         "v":"w", "w":"x", "x":"y", "y":"z",
#     }
#     sin = list_1  #待加密字符串
#     sjn = ""  #加密后字符串
#     for x in sin:
#         sjn += dictionary_1[x]
#     return sjn
#
# s3 = "encryption"
# skn = encrypt(s3)
# print(skn)




















